﻿using System;

namespace KMLHelper
{
    public class KMLPoint : KMLGeometry
    {
        private KMLVector3 coord;
        /// <summary>
        /// 轨迹点的坐标
        /// </summary>
        public KMLVector3 Coord
        {
            set { this.coord = value; }
        }

        private string timeStamp = null;
        /// <summary>
        /// 轨迹点的时间
        /// </summary>
        public string TimeStr
        {
            set 
            {
                DateTime time = DateTime.Now;
                if (DateTime.TryParse(value, out time))
                {
                    this.timeStamp = time.ToString(KMLConstant.TimeFormat);
                }
            }
        }
        /// <summary>
        /// 轨迹点的时间
        /// </summary>
        public DateTime Time
        {
            set
            {
                this.timeStamp = value.ToString(KMLConstant.TimeFormat);
            }
        }

        public KMLPoint()
        {
            this.geoType = EnumKMLGeoType.Point;
        }

        public override void Write(System.IO.StreamWriter sw)
        {
            try
            {
                sw.WriteLine("<Point>");
                sw.WriteLine("<extrude>" + this.extrude.ToString() + "</extrude>");
                if (this.altitudeMode != EnumKMLAltitudeMode.NULL)
                {
                    sw.WriteLine("<altitudeMode>" + this.GetAltitudeMode() + "</altitudeMode>");
                }
                sw.WriteLine("<coordinates>" + this.coord.Longitude + "," + this.coord.Latitude + "," + this.coord.Elevation + "</coordinates>");
                sw.WriteLine("</Point>");
                if (string.IsNullOrEmpty(this.timeStamp) == false)
                {
                    sw.WriteLine("<TimeStamp>");
                    sw.WriteLine("<when>" + this.timeStamp + "</when>");
                    sw.WriteLine("</TimeStamp>");
                }
            }
            catch
            { throw; }
        }
    }
}
